Hi,
I am new to DXL and would like to know the syntax to check to see if the file that the following code is opening exists before trying to open it. If it does not exist, I would like to create it. Please help!! TIA
bool excelInit()
{
string ExcelFileName = ThisModule."ICP_DOORS_Report_Path" "ICP_Metrics.xls" //ICP_DOORS_Report_Path is an attribute in the DOORS module
objExcel = connectToApp(cObjExcelApplication, "Excel")
if (null objExcel) return false
makeVisible objExcel
// get workbooks collection
checkRes(oleGet(objExcel,cPropertyWorkbooks,objWorkbooks))
if (null objWorkbooks)
{
ack "Unable to get workbooks collection"
return false
}
// Open existing Excel file
clear( args )
put( args, cParamFileName, ExcelFileName )
checkRes( oleMethod( objWorkbooks, cMethodOpen, args ) )
// get active workbook
checkRes(oleGet(objExcel,cPropertyActiveWorkbook,objWorkbook))
if (null objWorkbook)
{
ack "Unable to get active workbook"
return false
}
//get the worksheets
checkRes(oleGet(objWorkbook, "Worksheets", objWorksheets))
if (null objWorksheets)
{
ack "Unable to get worksheets"
return false
}
clear(args )
put(args, dataSheetName)
checkRes( oleGet(objWorksheets,"Item", args , objSheet) )
if (null objSheet)
{
ack "Unable to get Sheet"
return false
}
// Activate selected sheet
checkRes( oleMethod(objSheet, "Activate") )
return true
}
SystemAdmin - Mon Jul 27 14:26:32 EDT 2009 |
|
Re: If file does not exist llandale - Mon Jul 27 16:39:57 EDT 2009
To insert code inline to a posting, surround it with /{code/} (w/o the slashes) starting in the first column.
I have trouble follow, partly because of the above and partly because I don't do much OLE automation.
The following function is from the DXL manual, it appears to return true of the Name is a Windows file or a Windows folder:
bool fileExists_(string filename) {
Stat s
s = create filename
if (null s) return false
delete s
return true
}
This is the one I wrote many years ago, I'm sure it works better but I don't recall why:
//*********************
bool fIsFile(string NameFile)
{ // Does the named windows file actually exist.
return(!null NameFile and canOpenFile(NameFile, false))
} // end fIsFile()
In any case, you can create the file using the Stat = write(fileName) command, and you won't have to check if it already exists.
|
|
Re: If file does not exist SystemAdmin - Tue Jul 28 01:09:07 EDT 2009 llandale - Mon Jul 27 16:39:57 EDT 2009
To insert code inline to a posting, surround it with /{code/} (w/o the slashes) starting in the first column.
I have trouble follow, partly because of the above and partly because I don't do much OLE automation.
The following function is from the DXL manual, it appears to return true of the Name is a Windows file or a Windows folder:
bool fileExists_(string filename) {
Stat s
s = create filename
if (null s) return false
delete s
return true
}
This is the one I wrote many years ago, I'm sure it works better but I don't recall why:
//*********************
bool fIsFile(string NameFile)
{ // Does the named windows file actually exist.
return(!null NameFile and canOpenFile(NameFile, false))
} // end fIsFile()
In any case, you can create the file using the Stat = write(fileName) command, and you won't have to check if it already exists.
And for more file related functions look for file "fileops.dxl" in lib\dxl\utils below youw DOORS installation directory.
|
|
Re: If file does not exist SystemAdmin - Wed Jul 29 13:28:12 EDT 2009
Thanks a lot! This helps. Can you tell me how to make the file Read-Write. When it opens the file that I created, it opens in Read-Only.
write ExcelFileName
|
|
Re: If file does not exist dpechacek - Tue Aug 04 12:10:12 EDT 2009 SystemAdmin - Wed Jul 29 13:28:12 EDT 2009
Thanks a lot! This helps. Can you tell me how to make the file Read-Write. When it opens the file that I created, it opens in Read-Only.
write ExcelFileName
To write to a file, use a Stream.
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
|
|
Re: If file does not exist dpechacek - Tue Aug 04 12:11:04 EDT 2009 dpechacek - Tue Aug 04 12:10:12 EDT 2009
To write to a file, use a Stream.
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
If you're trying to write to an excel file though, you need to use OLE Objects.
See my excel functions @ www.baselinesinc.com
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
|
|